package com.microstation.spring.config;

import com.microstation.interceptor.CookieInterceptor;
import com.microstation.interceptor.SigninCookieInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.nio.charset.Charset;
import java.util.List;

@Configuration
public class SigninCookieInterceptorConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        HandlerInterceptor handlerInterceptor = new SigninCookieInterceptor();
        //super.addInterceptors(registry);
        registry.addInterceptor(handlerInterceptor)
                .addPathPatterns("/api/signin/**")
                .excludePathPatterns("/api/signin/toSignin", "/api/signin/login");
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        converters.add(converter);
    }
}
